package com.zygh.policeasset.service;


import cn.afterturn.easypoi.entity.vo.NormalExcelConstants;
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sun.xml.bind.v2.runtime.reflect.opt.Const;
import com.zygh.policeasset.component.CommonResult;
import com.zygh.policeasset.component.ExcelDataHand.ExcelDataHandBasics;
import com.zygh.policeasset.component.ExcelDataHand.ExcelDataHandHardwit;
import com.zygh.policeasset.component.ExcelDataHand.ExcelDataHandPurchase;
import com.zygh.policeasset.component.ExcelDataHand.ExcelDataHandSoftwit;
import com.zygh.policeasset.component.ReportComponent;
import com.zygh.policeasset.mapper.AssetsImagesMapper;
import com.zygh.policeasset.mapper.AssetsMapper;
import com.zygh.policeasset.mapper.BasicsMapper;
import com.zygh.policeasset.mapper.DailyAssetMapper;
import com.zygh.policeasset.mapper.DailyProjectMapper;
import com.zygh.policeasset.mapper.ExcelMapper;
import com.zygh.policeasset.mapper.HardwitMapper;
import com.zygh.policeasset.mapper.ImagesMapper;
import com.zygh.policeasset.mapper.ProjectMapper;
import com.zygh.policeasset.mapper.PurchaseMapper;
import com.zygh.policeasset.mapper.SettlementMapper;
import com.zygh.policeasset.mapper.SoftwitMapper;
import com.zygh.policeasset.mapper.UploadFileMapper;
import com.zygh.policeasset.pojo.AssetsImages;
import com.zygh.policeasset.pojo.Basics;
import com.zygh.policeasset.pojo.DailyAsset;
import com.zygh.policeasset.pojo.DailyProject;
import com.zygh.policeasset.pojo.DepRate;
import com.zygh.policeasset.pojo.GetReportCount;
import com.zygh.policeasset.pojo.Hardwit;
import com.zygh.policeasset.pojo.Purchase;
import com.zygh.policeasset.pojo.Report;
import com.zygh.policeasset.pojo.Softwit;
import com.zygh.policeasset.pojo.UploadFile;
import com.zygh.policeasset.pojo.export.ExportBasics;
import com.zygh.policeasset.pojo.export.ExportHardwit;
import com.zygh.policeasset.pojo.export.ExportPurchase;
import com.zygh.policeasset.pojo.export.ExportSoftWit;
import com.zygh.policeasset.pojo.vo.ProjectInfoVO;
import com.zygh.policeasset.utils.DepRateByTimeUtil;
import com.zygh.policeasset.utils.EasyExcelUtil;
import com.zygh.policeasset.utils.ExcelUtil;
import com.zygh.policeasset.utils.ZipUtils;

import java.io.*;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletResponse;
import org.apache.poi.ss.usermodel.ClientAnchor;
import org.apache.poi.ss.usermodel.Drawing;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.servlet.tags.form.AbstractHtmlElementTag;

@Service
/* loaded from: police-asset-2.0-0.0.1-SNAPSHOT.jar:BOOT-INF/classes/com/zygh/policeasset/service/ExcelService.class */
public class ExcelService {
    @Autowired
    HardwitMapper hardwitMapper;
    @Autowired
    AssetsMapper assetsMapper;
    @Autowired
    SoftwitMapper softwitMapper;
    @Autowired
    BasicsMapper basicsMapper;
    @Autowired
    PurchaseMapper purchaseMapper;
    @Autowired
    DailyAssetMapper dailyAssetMapper;
    @Autowired
    ExcelMapper excelMapper;
    @Autowired
    DailyAssetsService dailyAssetsService;
    @Autowired
    ReportComponent reportComponent;
    @Autowired
    EasyExcelUtil easyExcelUtil;
    @Value("${file.export}")
    String exportUrl;
    @Value("${nginx.url}")
    String nginxUrl;
    @Autowired
    ImagesMapper imagesMapper;
    @Autowired
    UploadFileMapper uploadFileMapper;
    @Autowired
    AssetsImagesMapper assetsImagesMapper;
    @Autowired
    SettlementMapper settlementMapper;
    @Autowired
    DailyProjectMapper dailyProjectMapper;
    @Autowired
    ProjectMapper projectMapper;
    @Autowired
    DepRateByTimeUtil depRateByTimeUtil;

    public List<DepRate> depratebytimeNew(String startTime, String endTime, String time1, String time2, Integer condition, Integer dataLabelsId, Integer assetsClassificationId, Integer assetsClassificationPid) throws ParseException, IllegalAccessException {
        return new DepRateByTimeUtil().getDepRateNew(this.excelMapper.getDepRateNew(startTime, endTime, dataLabelsId, assetsClassificationId, assetsClassificationPid, condition), time1, time2, condition);
    }

    public String depratebytimeNewExport(String startTime, String endTime, String time1, String time2, Integer condition, Integer dataLabelsId, Integer assetsClassificationId, Integer assetsClassificationPid, HttpServletResponse response) throws ParseException, IllegalAccessException {
        return this.easyExcelUtil.depratebytimeNewExport(response, new DepRateByTimeUtil().getDepRateNew(this.excelMapper.getDepRateNew(startTime, endTime, dataLabelsId, assetsClassificationId, assetsClassificationPid, condition), time1, time2, condition));
    }

    public String getExcel(HttpServletResponse response, Integer sectionId, String buildNum, String type) {
        String str = DateUtil.now().replaceAll("[[\\s-:punct:]]", "");
        String excelurl = this.exportUrl + str + "/" + str + ".xls";
        String excelfile = this.exportUrl + str;
        String zipUrl = null;
        File folder = new File(excelfile);
        if (!folder.exists() && !folder.isDirectory()) {
            folder.mkdirs();
        }
        try {
            if ("znh".equals(type) || "zns".equals(type) || "zn".equals(type)) {
                List<ExportHardwit> hardwitList = this.assetsMapper.exportHardwit(buildNum, sectionId, "znh");
                if (hardwitList.size() > 0) {
                    for (ExportHardwit exportHardwit : hardwitList) {
                        if (exportHardwit.getWhetherEnable().intValue() == 0) {
                            exportHardwit.setWhetherEnableName("未启用");
                        } else {
                            exportHardwit.setWhetherEnableName("已启用");
                        }
                        AssetsImages images = this.assetsImagesMapper.findByAssetsId(exportHardwit.getId());
                        if (images != null) {
                            downloadPicture(images.getConnect(), excelfile + "/" + images.getConnect().substring(images.getConnect().lastIndexOf("/") + 1) + ".jpg");
                            exportHardwit.setPicurl(images.getConnect().substring(images.getConnect().lastIndexOf("/") + 1) + ".jpg");
                            exportHardwit.setPic("照片");
                        } else {
                            exportHardwit.setPicurl("");
                        }
                    }
                }
                List<ExportSoftWit> softwitList = this.assetsMapper.exportSoftwit(buildNum, sectionId, "zns");
                if (softwitList.size() > 0) {
                    for (ExportSoftWit exportSoftWit : softwitList) {
                        if (exportSoftWit.getWhetherEnable().intValue() == 0) {
                            exportSoftWit.setWhetherEnableName("未启用");
                        } else {
                            exportSoftWit.setWhetherEnableName("已启用");
                        }
                        AssetsImages images2 = this.assetsImagesMapper.findByAssetsId(exportSoftWit.getId());
                        if (images2 != null) {
                            downloadPicture(images2.getConnect(), excelfile + "/" + images2.getConnect().substring(images2.getConnect().lastIndexOf("/") + 1) + ".jpg");
                            exportSoftWit.setPicurl(images2.getConnect().substring(images2.getConnect().lastIndexOf("/") + 1) + ".jpg");
                            exportSoftWit.setPic("照片");
                        } else {
                            exportSoftWit.setPicurl("");
                        }
                    }
                }
                downExportHardwit(excelurl, response, hardwitList, softwitList);
                zipUrl = excelfile + ".zip";
                ZipUtils.toZip(excelfile, new FileOutputStream(new File(zipUrl)), true);
            } else if ("jc".equals(type)) {
                List<ExportBasics> basicsList = this.assetsMapper.exportBasics(buildNum, sectionId, "jc");
                if (basicsList.size() == 0) {
                    return "无资产数据！";
                }
                for (ExportBasics exportBasics : basicsList) {
                    AssetsImages images3 = this.assetsImagesMapper.findByAssetsId(exportBasics.getId());
                    if (images3 != null) {
                        downloadPicture(images3.getConnect(), excelfile + "/" + images3.getConnect().substring(images3.getConnect().lastIndexOf("/") + 1) + ".jpg");
                        exportBasics.setPicurl(images3.getConnect().substring(images3.getConnect().lastIndexOf("/") + 1) + ".jpg");
                        exportBasics.setPic("照片");
                    } else {
                        exportBasics.setPicurl("");
                    }
                }
                downExportBasics(excelurl, response, basicsList);
                zipUrl = excelfile + ".zip";
                ZipUtils.toZip(excelfile, new FileOutputStream(new File(zipUrl)), true);
            } else if ("cg".equals(type)) {
                List<ExportPurchase> purchaseList = this.assetsMapper.exportPurchase(buildNum, "cg");
                if (purchaseList.size() == 0) {
                    return "无资产数据！";
                }
                for (ExportPurchase exportPurchase : purchaseList) {
                    AssetsImages images4 = this.assetsImagesMapper.findByAssetsId(exportPurchase.getId());
                    if (images4 != null) {
                        downloadPicture(images4.getConnect(), excelfile + "/" + images4.getConnect().substring(images4.getConnect().lastIndexOf("/") + 1) + ".jpg");
                        exportPurchase.setPicurl(images4.getConnect().substring(images4.getConnect().lastIndexOf("/") + 1) + ".jpg");
                        exportPurchase.setPic("照片");
                    } else {
                        exportPurchase.setPicurl("");
                    }
                }
                downExportPurchase(excelurl, response, purchaseList);
                zipUrl = excelfile + ".zip";
                ZipUtils.toZip(excelfile, new FileOutputStream(new File(zipUrl)), true);
            } else if ("da".equals(type)) {
                List<ExportBasics> dailyAssetList = this.assetsMapper.exportBasics(buildNum, null, "da");
                if (dailyAssetList.size() == 0) {
                    return "无资产数据！";
                }
                for (ExportBasics exportBasics2 : dailyAssetList) {
                    AssetsImages images5 = this.assetsImagesMapper.findByAssetsId(exportBasics2.getId());
                    if (images5 != null) {
                        downloadPicture(images5.getConnect(), excelfile + "/" + images5.getConnect().substring(images5.getConnect().lastIndexOf("/") + 1));
                        exportBasics2.setPicurl(images5.getConnect().substring(images5.getConnect().lastIndexOf("/") + 1));
                        exportBasics2.setPic("照片");
                    } else {
                        exportBasics2.setPicurl("");
                    }
                }
                for (UploadFile uploadFile : this.uploadFileMapper.findByIdType(Integer.parseInt(buildNum), "daily", 0)) {
                    downloadPicture(uploadFile.getContent(), excelfile + "/" + uploadFile.getContent().substring(uploadFile.getContent().lastIndexOf("/") + 1));
                }
                downExportBasics(excelurl, response, dailyAssetList);
                zipUrl = excelfile + ".zip";
                ZipUtils.toZip(excelfile, new FileOutputStream(new File(zipUrl)), true);
            }
            System.out.println(zipUrl);
            return this.nginxUrl + zipUrl.replaceAll(this.exportUrl, "assetsExcel/");
        } catch (Exception e) {
            e.printStackTrace();
            return "导出失败！";
        }
    }

    public CommonResult getAssetCard(Integer sectionId, String buildNum, String type) throws IOException {
        Workbook workbook = null;
        List<ExportBasics> dailyAssetList = null;
        int lasetCol;
        if (StrUtil.isEmpty(buildNum)) {
            return new CommonResult().validateFailed("项目编号不能为空");
        }
        if (StrUtil.isEmpty(type)) {
            return new CommonResult().validateFailed("类型不能为空");
        }
        String str = DateUtil.now().replaceAll("[[\\s-:punct:]]", "");
        String excelurl = this.exportUrl + str + "/" + str + ".xls";
        File folder = new File(this.exportUrl + str);
        if (!folder.exists() && !folder.isDirectory()) {
            folder.mkdirs();
        }
        try {
            workbook = new XSSFWorkbook();
            try {
                dailyAssetList = this.assetsMapper.exportBasics(buildNum, sectionId, type);
            } catch (Exception e) {
                e.printStackTrace();
                return new CommonResult().validateFailed("导出失败！");
            }
        } catch (Exception e2) {
            e2.printStackTrace();
        }
        if (dailyAssetList.size() == 0) {
            return new CommonResult().validateFailed("无资产数据！");
        }
        for (int i = 0; i < dailyAssetList.size(); i++) {
            Sheet sheet = workbook.createSheet("资产" + (i + 1));
            AssetsImages images = this.assetsImagesMapper.findByAssetsId(dailyAssetList.get(i).getId());
            if (!StringUtils.isEmpty(images)) {
                ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();
                ImageIO.write(ImageIO.read(new URL(images.getConnect()).openStream()), "jpg", byteArrayOut);
                Drawing patriarch = sheet.createDrawingPatriarch();
                XSSFClientAnchor anchor = new XSSFClientAnchor(100, 100, 100, 100, 4, 2, 7, 11);
                anchor.setAnchorType(ClientAnchor.AnchorType.DONT_MOVE_AND_RESIZE);
                patriarch.createPicture(anchor, workbook.addPicture(byteArrayOut.toByteArray(), 5));
            }
            for (int j = 0; j < 11; j++) {
                if (j == 0 || j == 1) {
                    lasetCol = 6;
                } else {
                    lasetCol = 3;
                }
                sheet.addMergedRegion(new CellRangeAddress(j, j, 0, lasetCol));
            }
            sheet.addMergedRegion(new CellRangeAddress(2, 10, 4, 6));
            sheet.createRow(0).createCell(0).setCellValue("资产编号：" + dailyAssetList.get(i).getAssetNum());
            sheet.createRow(1).createCell(0).setCellValue("智能交通");
            sheet.createRow(2).createCell(0).setCellValue("资产编号：" + dailyAssetList.get(i).getAssetNum());
            sheet.createRow(3).createCell(0).setCellValue("资产类别：" + dailyAssetList.get(i).getWitbigName() + "/" + dailyAssetList.get(i).getWitsmallName());
            sheet.createRow(4).createCell(0).setCellValue("启用时间：" + dailyAssetList.get(i).getStartDatetime());
            sheet.createRow(5).createCell(0).setCellValue("启用价值：" + dailyAssetList.get(i).getUnitPrice());
            sheet.createRow(6).createCell(0).setCellValue("预计使用年限：" + dailyAssetList.get(i).getDepreciationYear());
            sheet.createRow(7).createCell(0).setCellValue("品牌名称：" + dailyAssetList.get(i).getBrand());
            sheet.createRow(8).createCell(0).setCellValue("承建单位：" + dailyAssetList.get(i).getBuildName());
            sheet.createRow(9).createCell(0).setCellValue("建设单位：：" + dailyAssetList.get(i).getConstrucName());
            sheet.createRow(10).createCell(0).setCellValue("存放地点：" + dailyAssetList.get(i).getPlace());
        }
        FileOutputStream fileOutputStream = new FileOutputStream(excelurl);
        workbook.write(fileOutputStream);
        fileOutputStream.close();
        return new CommonResult().success(this.nginxUrl + excelurl.replaceAll(this.exportUrl, "assetsExcel/"));
    }

    public void downExportBasics(String excelfile, HttpServletResponse response, List<ExportBasics> exportExcels) throws IOException {
        response.setCharacterEncoding("UTF-8");
        ExportParams params = new ExportParams(null, "数据统计");
        params.setDataHandler(new ExcelDataHandBasics());
        Workbook workbook = ExcelExportUtil.exportExcel(params, ExportBasics.class, exportExcels);
        FileOutputStream fos = new FileOutputStream(excelfile);
        workbook.write(fos);
        fos.close();
    }

    public void downExport(String excelfile, HttpServletResponse response, List<ExportBasics> exportExcels) throws IOException {
        response.setCharacterEncoding("UTF-8");
        ExportParams params = new ExportParams(null, "数据统计");
        params.setDataHandler(new ExcelDataHandBasics());
        Workbook workbook = ExcelExportUtil.exportExcel(params, ExportBasics.class, exportExcels);
        FileOutputStream fos = new FileOutputStream(excelfile);
        workbook.write(fos);
        fos.close();
    }

    public void downExportSoftwit(String excelfile, HttpServletResponse response, List<ExportSoftWit> exportExcels) throws IOException {
        response.setCharacterEncoding("UTF-8");
        ExportParams params = new ExportParams(null, "数据统计");
        params.setDataHandler(new ExcelDataHandSoftwit());
        Workbook workbook = ExcelExportUtil.exportExcel(params, ExportSoftWit.class, exportExcels);
        FileOutputStream fos = new FileOutputStream(excelfile);
        workbook.write(fos);
        fos.close();
    }

    public void downExportPurchase(String excelfile, HttpServletResponse response, List<ExportPurchase> exportExcels) throws IOException {
        response.setCharacterEncoding("UTF-8");
        ExportParams params = new ExportParams(null, "数据统计");
        params.setDataHandler(new ExcelDataHandPurchase());
        Workbook workbook = ExcelExportUtil.exportExcel(params, ExportPurchase.class, exportExcels);
        FileOutputStream fos = new FileOutputStream(excelfile);
        workbook.write(fos);
        fos.close();
    }

    public void downExportHardwit(String excelfile, HttpServletResponse response, List<ExportHardwit> exportHardwitList, List<ExportSoftWit> exportSoftWitList) throws IOException {
        response.setCharacterEncoding("UTF-8");
        ExportParams params = new ExportParams(null, "智能硬件资产");
        ExportParams params1 = new ExportParams(null, "智能软件资产");
        params.setDataHandler(new ExcelDataHandHardwit());
        params1.setDataHandler(new ExcelDataHandSoftwit());
        Map<String, Object> hashMap = new HashMap<>();
        Map<String, Object> hashMap2 = new HashMap<>();
        hashMap.put(NormalExcelConstants.DATA_LIST, exportHardwitList);
       // hashMap.put(BasePOIConstants.CLASS, ExportHardwit.class);
        hashMap.put(AbstractHtmlElementTag.TITLE_ATTRIBUTE, params);
        hashMap2.put(NormalExcelConstants.DATA_LIST, exportSoftWitList);
        //hashMap2.put(BasePOIConstants.CLASS, ExportSoftWit.class);
        hashMap2.put(AbstractHtmlElementTag.TITLE_ATTRIBUTE, params1);
        List<Map<String, Object>> sheetsList = new ArrayList<>();
        sheetsList.add(hashMap);
        sheetsList.add(hashMap2);
        Workbook workbook = ExcelExportUtil.exportExcel(sheetsList, ExcelType.HSSF);
        FileOutputStream fos = new FileOutputStream(excelfile);
        workbook.write(fos);
        fos.close();
    }

    private static void downloadPicture(String urlList, String path) {
        try {
            DataInputStream dataInputStream = new DataInputStream(new URL(urlList).openStream());
            FileOutputStream fileOutputStream = new FileOutputStream(new File(path));
            ByteArrayOutputStream output = new ByteArrayOutputStream();
            byte[] buffer = new byte[1024];
            while (true) {
                int length = dataInputStream.read(buffer);
                if (length > 0) {
                    output.write(buffer, 0, length);
                } else {
                    fileOutputStream.write(output.toByteArray());
                    dataInputStream.close();
                    fileOutputStream.close();
                    return;
                }
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e2) {
            e2.printStackTrace();
        }
    }

    public PageInfo<GetReportCount> reportCount(int pageNum, int pageSize, String startTime, String endTime, String type) {
        List<GetReportCount> reportList = new ArrayList();
        PageHelper.startPage(pageNum, pageSize);
        if ("zn".equals(type)) {
            reportList = this.excelMapper.getReportCountZn(startTime, endTime, 1);
        } else if ("jc".equals(type)) {
            reportList = this.excelMapper.getReportCountZn(startTime, endTime, 2);
        } else if ("cg".equals(type)) {
            reportList = this.excelMapper.getReportCountCg(startTime, endTime);
        } else if ("da".equals(type)) {
            reportList = this.excelMapper.getReportCountDa(startTime, endTime);
        }
        return new PageInfo<>(reportList);
    }

    public List<Report> report(String type, String startTime, String endTime) throws ParseException, ExecutionException, InterruptedException {
        List<Report> reportList = new ArrayList();
        if ("".equals(type) || type == null) {
            CompletableFuture<List<Report>> r1 = this.reportComponent.get(this.excelMapper.getReportZnhw(startTime, endTime, 1), "智能");
            CompletableFuture<List<Report>> r3 = this.reportComponent.get(this.excelMapper.getReportZnhw(startTime, endTime, 2), "基础");
            CompletableFuture<List<Report>> r4 = this.reportComponent.get(this.excelMapper.getReportCg(startTime, endTime), "采购");
            CompletableFuture<List<Report>> r5 = this.reportComponent.get(this.excelMapper.getReportDa(startTime, endTime), "日常");
            if (r1.get() != null) {
                reportList.addAll(r1.get());
            }
            if (r3.get() != null) {
                reportList.addAll(r3.get());
            }
            if (r4.get() != null) {
                reportList.addAll(r4.get());
            }
            if (r5.get() != null) {
                reportList.addAll(r5.get());
            }
        } else if ("zn".equals(type)) {
            CompletableFuture<List<Report>> r12 = this.reportComponent.get(this.excelMapper.getReportZnhw(startTime, endTime, 1), "智能");
            if (r12.get() != null) {
                reportList.addAll(r12.get());
            }
        } else if ("jc".equals(type)) {
            CompletableFuture<List<Report>> r2 = this.reportComponent.get(this.excelMapper.getReportZnhw(startTime, endTime, 2), "基础");
            if (r2.get() != null) {
                reportList = r2.get();
            }
        } else if ("zd".equals(type)) {
            CompletableFuture<List<Report>> r32 = this.reportComponent.get(this.excelMapper.getReportCg(startTime, endTime), "采购");
            if (r32.get() != null) {
                reportList = r32.get();
            }
        } else if ("da".equals(type)) {
            CompletableFuture<List<Report>> r33 = this.reportComponent.get(this.excelMapper.getReportDa(startTime, endTime), "日常");
            if (r33.get() != null) {
                reportList = r33.get();
            }
        }
        return reportList;
    }

    public List<Report> getcg(List<Report> list) throws ParseException {
        List<Report> reportList = new ArrayList<>();
        for (Report basics : list) {
            List<Purchase> purchaseList = this.purchaseMapper.findByProjectNo(basics.getProjectNo());
            Double sum = Double.valueOf((double) Const.default_value_double);
            Double zje = Double.valueOf((double) Const.default_value_double);
            for (Purchase purchase : purchaseList) {
                Double a = Double.valueOf(Double.parseDouble(purchase.getMoney()));
                sum = Double.valueOf(sum.doubleValue() + a.doubleValue());
                zje = Double.valueOf(zje.doubleValue() + ((a.doubleValue() / ((double) (Integer.parseInt(purchase.getDepreciationYear()) * 12))) * ((double) getCountMonth(purchase.getGetDatetime()))));
            }
            BigDecimal sum1 = new BigDecimal(sum.doubleValue()).setScale(2, RoundingMode.UP);
            BigDecimal zje1 = new BigDecimal(zje.doubleValue()).setScale(2, RoundingMode.UP);
            Report report = new Report();
            report.setName(basics.getName());
            report.setType("采购");
            report.setProjectNo(basics.getProjectNo());
            report.setSum(String.valueOf(sum1));
            if (zje.doubleValue() > sum.doubleValue()) {
                report.setNumber1(String.valueOf(sum1));
                report.setNumber2("0");
            } else {
                report.setNumber1(String.valueOf(zje1));
                report.setNumber2(String.valueOf(sum1.subtract(zje1).doubleValue()));
            }
            reportList.add(report);
            System.out.println(report);
        }
        return reportList;
    }

    public List<Report> getjc(List<Report> list) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        List<Report> reportList = new ArrayList<>();
        for (Report basics : list) {
            List<Basics> basicsList = this.basicsMapper.findBySectionId(basics.getSectionId());
            Double sum = Double.valueOf((double) Const.default_value_double);
            Double zje = Double.valueOf((double) Const.default_value_double);
            for (Basics basics1 : basicsList) {
                Double a = Double.valueOf(((double) basics1.getNumber().intValue()) * Double.parseDouble(basics1.getStartMoney()));
                sum = Double.valueOf(sum.doubleValue() + a.doubleValue());
                if (sdf.parse("2020-01-01").before(sdf.parse(basics1.getStopTime()))) {
                    zje = Double.valueOf(zje.doubleValue() + ((a.doubleValue() / ((double) (basics1.getDepreciationPeriod().intValue() * 12))) * ((double) getCountMonth(basics1.getAudit_time()))));
                } else {
                    zje = Double.valueOf(zje.doubleValue() + ((a.doubleValue() / ((double) (basics1.getDepreciationPeriod().intValue() * 12))) * ((double) getCountMonth(basics1.getStopTime()))));
                }
            }
            BigDecimal sum1 = new BigDecimal(sum.doubleValue()).setScale(2, RoundingMode.UP);
            BigDecimal zje1 = new BigDecimal(zje.doubleValue()).setScale(2, RoundingMode.UP);
            Report report = new Report();
            report.setName(basics.getName());
            report.setType("基础");
            report.setProjectNo(basics.getProjectNo());
            report.setSectionName(basics.getSectionName());
            report.setSectionId(basics.getSectionId());
            report.setSum(String.valueOf(sum1));
            if (zje.doubleValue() > sum.doubleValue()) {
                report.setNumber1(String.valueOf(sum1));
                report.setNumber2("0");
            } else {
                report.setNumber1(String.valueOf(zje1));
                report.setNumber2(String.valueOf(sum1.subtract(zje1).doubleValue()));
            }
            reportList.add(report);
        }
        return reportList;
    }

    public List<Report> getda(List<DailyProject> list) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        List<Report> reportList = new ArrayList<>();
        for (DailyProject basics : list) {
            List<DailyAsset> basicsList = this.dailyAssetsService.findAllBybuildNum(String.valueOf(basics.getId()));
            Double sum = Double.valueOf((double) Const.default_value_double);
            Double zje = Double.valueOf((double) Const.default_value_double);
            for (DailyAsset basics1 : basicsList) {
                Double a = Double.valueOf(((double) basics1.getNumber().intValue()) * Double.parseDouble(basics1.getStartMoney()));
                sum = Double.valueOf(sum.doubleValue() + a.doubleValue());
                if (sdf.parse("2020-01-01").before(sdf.parse(basics1.getStopTime()))) {
                    zje = Double.valueOf(zje.doubleValue() + ((a.doubleValue() / ((double) (basics1.getPlanYear().intValue() * 12))) * ((double) getCountMonth(basics1.getStopTime()))));
                } else {
                    zje = Double.valueOf(zje.doubleValue() + ((a.doubleValue() / ((double) (basics1.getPlanYear().intValue() * 12))) * ((double) getCountMonth(basics1.getStopTime()))));
                }
            }
            BigDecimal sum1 = new BigDecimal(sum.doubleValue()).setScale(2, RoundingMode.UP);
            BigDecimal zje1 = new BigDecimal(zje.doubleValue()).setScale(2, RoundingMode.UP);
            Report report = new Report();
            report.setName(basics.getProjectName());
            report.setType("日常资产");
            report.setSum(String.valueOf(sum1));
            if (zje.doubleValue() > sum.doubleValue()) {
                report.setNumber1(String.valueOf(sum1));
                report.setNumber2("0");
            } else {
                report.setNumber1(String.valueOf(zje1));
                report.setNumber2(String.valueOf(sum1.subtract(zje1).doubleValue()));
            }
            reportList.add(report);
        }
        return reportList;
    }

    public List<Report> getznhw(List<Report> list) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        List<Report> reportList = new ArrayList<>();
        for (Report report1 : list) {
            List<Hardwit> hardwitList = this.hardwitMapper.findBySectionId(report1.getSectionId());
            Double sum = Double.valueOf((double) Const.default_value_double);
            Double zje = Double.valueOf((double) Const.default_value_double);
            for (Hardwit hardwit : hardwitList) {
                Double a = Double.valueOf(Double.parseDouble(hardwit.getStartMoney()));
                sum = Double.valueOf(sum.doubleValue() + a.doubleValue());
                if (sdf.parse("2020-01-01").before(sdf.parse(hardwit.getStopTime()))) {
                    zje = Double.valueOf(zje.doubleValue() + ((a.doubleValue() / ((double) (hardwit.getDepreciationPeriod().intValue() * 12))) * ((double) getCountMonth(hardwit.getAudit_time()))));
                } else {
                    zje = Double.valueOf(zje.doubleValue() + ((a.doubleValue() / ((double) (hardwit.getDepreciationPeriod().intValue() * 12))) * ((double) getCountMonth(hardwit.getStopTime()))));
                }
            }
            List<Softwit> softwitList = this.softwitMapper.findBySectionId(report1.getSectionId());
            if (softwitList.size() > 0) {
                for (Softwit softwit : softwitList) {
                    Double a2 = Double.valueOf(Double.parseDouble(softwit.getStartMoney()));
                    sum = Double.valueOf(sum.doubleValue() + a2.doubleValue());
                    if (sdf.parse("2020-01-01").before(sdf.parse(softwit.getStopTime()))) {
                        System.out.println("按照内审时间折旧");
                        zje = Double.valueOf(zje.doubleValue() + ((a2.doubleValue() / ((double) (softwit.getDepreciationPeriod().intValue() * 12))) * ((double) getCountMonth(softwit.getAudit_time()))));
                    } else {
                        System.out.println("按照竣工验收时间折旧");
                        zje = Double.valueOf(zje.doubleValue() + ((a2.doubleValue() / ((double) (softwit.getDepreciationPeriod().intValue() * 12))) * ((double) getCountMonth(softwit.getStopTime()))));
                    }
                }
            }
            BigDecimal sum1 = new BigDecimal(sum.doubleValue()).setScale(2, RoundingMode.UP);
            BigDecimal zje1 = new BigDecimal(zje.doubleValue()).setScale(2, RoundingMode.UP);
            Report report = new Report();
            report.setName(report1.getName());
            report.setType("智能");
            report.setProjectNo(report1.getProjectNo());
            report.setSectionName(report1.getSectionName());
            report.setSectionId(report1.getSectionId());
            report.setSum(String.valueOf(sum1));
            if (zje.doubleValue() > sum.doubleValue()) {
                report.setNumber1(String.valueOf(sum1));
                report.setNumber2("0");
            } else {
                report.setNumber1(String.valueOf(zje1));
                report.setNumber2(String.valueOf(sum1.subtract(zje1).doubleValue()));
            }
            reportList.add(report);
        }
        return reportList;
    }

    public List<Report> getznsw(List<Report> list) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        List<Report> reportList = new ArrayList<>();
        for (Report report1 : list) {
            List<Softwit> softwitList = this.softwitMapper.findBySectionId(report1.getSectionId());
            List<Hardwit> hardwitList = this.hardwitMapper.findBySectionId(report1.getSectionId());
            if (softwitList.size() > 0 && hardwitList.size() == 0) {
                Double sum = Double.valueOf((double) Const.default_value_double);
                Double zje = Double.valueOf((double) Const.default_value_double);
                for (Softwit softwit : softwitList) {
                    Double a = Double.valueOf(Double.parseDouble(softwit.getStartMoney()));
                    sum = Double.valueOf(sum.doubleValue() + a.doubleValue());
                    if (sdf.parse("2020-01-01").before(sdf.parse(softwit.getStopTime()))) {
                        zje = Double.valueOf(zje.doubleValue() + ((a.doubleValue() / ((double) (Integer.parseInt(softwit.getPlanYear()) * 12))) * ((double) getCountMonth(softwit.getAudit_time()))));
                    } else {
                        zje = Double.valueOf(zje.doubleValue() + ((a.doubleValue() / ((double) (Integer.parseInt(softwit.getPlanYear()) * 12))) * ((double) getCountMonth(softwit.getStopTime()))));
                    }
                }
                BigDecimal sum1 = new BigDecimal(sum.doubleValue()).setScale(2, RoundingMode.UP);
                BigDecimal zje1 = new BigDecimal(zje.doubleValue()).setScale(2, RoundingMode.UP);
                Report report = new Report();
                report.setName(report1.getName());
                report.setType("智能");
                report.setProjectNo(report1.getProjectNo());
                report.setSectionName(report1.getSectionName());
                report.setSectionId(report1.getSectionId());
                report.setSum(String.valueOf(sum1));
                if (zje.doubleValue() > sum.doubleValue()) {
                    report.setNumber1(String.valueOf(sum1));
                    report.setNumber2("0");
                } else {
                    report.setNumber1(String.valueOf(zje1));
                    report.setNumber2(String.valueOf(sum1.subtract(zje1).doubleValue()));
                }
                reportList.add(report);
            }
        }
        return reportList;
    }

    public int getCountMonth(String time1) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
        String nowTime = sdf.format(new Date());
        Calendar bef = Calendar.getInstance();
        Calendar aft = Calendar.getInstance();
        bef.setTime(sdf.parse(time1));
        aft.setTime(sdf.parse(nowTime));
        return Math.abs(((aft.get(1) - bef.get(1)) * 12) + (aft.get(2) - bef.get(2)));
    }

    public String getReport(String type, String startTime, String endTime) throws Exception {
        String excel;
        if ("".equals(type) || type == null) {
            excel = "E:police-assets/assetsExcel/" + System.currentTimeMillis() + "资产报表.xls";
        } else {
            excel = "E:police-assets/assetsExcel/" + System.currentTimeMillis() + type + "资产报表.xls";
        }
        ExcelUtil excelUtil = new ExcelUtil();
        List<Report> reportList = new ArrayList<>();
        if ("".equals(type) || type == null) {
            CompletableFuture<List<Report>> hw = this.reportComponent.get(this.excelMapper.getReportZnhw(startTime, endTime, 1), "智能");
            CompletableFuture<List<Report>> jc = this.reportComponent.get(this.excelMapper.getReportZnhw(startTime, endTime, 2), "基础");
            CompletableFuture<List<Report>> cg = this.reportComponent.get(this.excelMapper.getReportCg(startTime, endTime), "采购");
            CompletableFuture<List<Report>> da = this.reportComponent.get(this.excelMapper.getReportDa(startTime, endTime), "日常");
            reportList.addAll(jc.get());
            reportList.addAll(hw.get());
            reportList.addAll(cg.get());
            reportList.addAll(da.get());
        } else if ("zn".equals(type)) {
            reportList.addAll(this.reportComponent.get(this.excelMapper.getReportZnhw(startTime, endTime, 1), "智能").get());
        } else if ("jc".equals(type)) {
            reportList.addAll(this.reportComponent.get(this.excelMapper.getReportZnhw(startTime, endTime, 2), "基础").get());
        } else if ("zd".equals(type)) {
            reportList.addAll(this.reportComponent.get(this.excelMapper.getReportCg(startTime, endTime), "采购").get());
        } else if ("da".equals(type)) {
            reportList.addAll(this.reportComponent.get(this.excelMapper.getReportDa(startTime, endTime), "日常").get());
        }
        if (reportList == null || reportList.size() == 0) {
            return "无资产数据！";
        }
        return this.nginxUrl + excelUtil.getReport(excel, reportList);
    }

    public DepRate setProjectName(DepRate depRate) {
        if ("jc".equals(depRate.getAssetsType()) || "znh".equals(depRate.getAssetsType()) || "zns".equals(depRate.getAssetsType())) {
            List<ProjectInfoVO> list = this.settlementMapper.getProjectInfo(null, depRate.getBuildNum(), depRate.getSectionId(), null, null);
            if (list.size() > 0) {
                depRate.setProjectName(list.get(0).getProjectName());
                depRate.setSectionName(list.get(0).getSectionName());
            }
        } else if ("cg".equals(depRate.getAssetsType())) {
            List<ProjectInfoVO> list2 = this.projectMapper.getProjectInfo(null, depRate.getBuildNum(), null, null, null);
            if (list2.size() > 0) {
                depRate.setProjectName(list2.get(0).getProjectName());
            }
        } else if ("da".equals(depRate.getAssetsType())) {
            List<ProjectInfoVO> list3 = this.dailyProjectMapper.getProjectInfo(null, depRate.getBuildNum(), null);
            if (list3.size() > 0) {
                depRate.setProjectName(list3.get(0).getProjectName());
                depRate.setSectionName(list3.get(0).getSectionName());
            }
        }
        return depRate;
    }
}